package com.lqm.entity.home;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonManagedReference;

import javax.persistence.*;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Objects;
import java.util.Set;

/**
 * @program: CrowdFunding
 * @description
 * @author: lqm
 * @create: 2018-12-06 17:28
 */

@Entity
@Table(name = "home_user", schema = "crowdfunding", catalog = "")
public class HomeUser implements Serializable {

    private Integer id;
    private String username;
    private String userNick;
    private String password;
    private String sex;
    private String userImg;
    private String userPhone;
    private String userEmail;
    private String ip;
    private Double account=0.0;

    @JsonFormat(shape = JsonFormat.Shape.STRING,pattern = "yyyy-MM-dd HH:mm:ss")
    private Timestamp createTime;
    private Integer status=1;
    @JsonManagedReference
    private Set<UserAddress> userAddresses;
    @JsonManagedReference
    private Set<Project> projects;

/*
    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        HomeUser homeUser = (HomeUser) o;
        return Objects.equals(id, homeUser.id) &&
                Objects.equals(username, homeUser.username) &&
                Objects.equals(userNick, homeUser.userNick) &&
                Objects.equals(password, homeUser.password) &&
                Objects.equals(sex, homeUser.sex) &&
                Objects.equals(userImg, homeUser.userImg) &&
                Objects.equals(userPhone, homeUser.userPhone) &&
                Objects.equals(userEmail, homeUser.userEmail) &&
                Objects.equals(ip, homeUser.ip) &&
                Objects.equals(createTime, homeUser.createTime) &&
                Objects.equals(status, homeUser.status) &&
                Objects.equals(userAddresses, homeUser.userAddresses) &&
                Objects.equals(projects, homeUser.projects);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, username, userNick, password, sex, userImg, userPhone, userEmail, ip, createTime, status, userAddresses, projects);
    }*/

    @Override
    public String toString() {
        return "HomeUser{" +
                "id=" + id +
                ", username='" + username + '\'' +
                ", userNick='" + userNick + '\'' +
                ", password='" + password + '\'' +
                ", sex='" + sex + '\'' +
                ", userImg='" + userImg + '\'' +
                ", userPhone='" + userPhone + '\'' +
                ", userEmail='" + userEmail + '\'' +
                ", ip='" + ip + '\'' +
                ", account=" + account +
                ", createTime=" + createTime +
                ", status=" + status +
                ", userAddresses=" + userAddresses +
                ", projects=" + projects +
                '}';
    }

    @Id
    @Column(name = "id", nullable = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @Basic
    @Column(name = "username", nullable = true, length = 30)
    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    @Basic
    @Column(name = "user_nick", nullable = true, length = 50)
    public String getUserNick() {
        return userNick;
    }

    public void setUserNick(String userNick) {
        this.userNick = userNick;
    }

    @Basic
    @Column(name = "password", nullable = true, length = 50)
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Basic
    @Column(name = "sex", nullable = true, length = 255)
    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    @Basic
    @Column(name = "user_img", nullable = true, length = 520)
    public String getUserImg() {
        return userImg;
    }

    public void setUserImg(String userImg) {
        this.userImg = userImg;
    }

    @Basic
    @Column(name = "user_phone", nullable = true, length = 11)
    public String getUserPhone() {
        return userPhone;
    }

    public void setUserPhone(String userPhone) {
        this.userPhone = userPhone;
    }

    @Basic
    @Column(name = "user_email", nullable = true, length = 100)
    public String getUserEmail() {
        return userEmail;
    }

    public void setUserEmail(String userEmail) {
        this.userEmail = userEmail;
    }

    @Basic
    @Column(name = "ip", nullable = true, length = 255)
    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    @Basic
    @Column(name = "create_time", nullable = true)
    public Timestamp getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Timestamp createTime) {
        this.createTime = createTime;
    }

    @Basic
    @Column(name = "status", nullable = false)
    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    @Basic
    @Column(name = "account", nullable = false)
    public Double getAccount() {
        return account;
    }

    public void setAccount(Double account) {
        this.account = account;
    }

    @OneToMany(mappedBy = "homeUser")
    public Set<UserAddress> getUserAddresses() {
        return userAddresses;
    }

    public void setUserAddresses(Set<UserAddress> userAddresses) {
        this.userAddresses = userAddresses;
    }


    @OneToMany(mappedBy = "homeUser")
    public Set<Project> getProjects() {
        return projects;
    }

    public void setProjects(Set<Project> projects) {
        this.projects = projects;
    }



}
